Skip to content

Conversation

@innocenzi
Copy link
Member

This pull request adds support for signed URIs. Additionally, it moves the URI generation methods from the Router interface to their own dedicated UriGenerator class.

Generating signed URIs can be done with their dedicated functions:

use function Tempest\signed_uri;
use function Tempest\temporary_signed_uri;

// unsubscribe link
signed_uri(
    action: [MailingListController::class, 'unsubscribe'],
    email: $email
);

// magic login link
temporary_signed_uri(
    action: PasswordlessAuthenticationController::class,
    duration: Duration::minutes(10),
    userId: $userId
);

To ensure a signature is valid, the hasValidSignature method should be called on the UriGenerator` class:

final class PasswordlessAuthenticationController
{
    public function __construct(
        private readonly UriGenerator $uri,
    ) {}

    public function __invoke(Request $request): Response
    {
        if (! $this->uri->hasValidSignature($request)) {
            return new Invalid();
        }

        // ...
    }
}

This pull request also moves the uri and is_current_uri from the Tempest namespace to the Tempest\Router namespace.

@brendt
Copy link
Member

brendt commented Aug 18, 2025

You'll have to update this one now that #1517 was merged

@innocenzi innocenzi merged commit 9d0fc5f into 2.x Aug 24, 2025
77 checks passed
@innocenzi innocenzi deleted the feat/signed-uris branch August 24, 2025 14:41
Bapawe pushed a commit to Bapawe/tempest-framework that referenced this pull request Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants